package com.tiantian.starter.autoconfigure;

import com.tiantian.starter.starter.YourStarterService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 定义配置类，自动配置类
 *
 * @Configuration： 表明这个类是一个配置类
 * @EnableConfigurationProperties(YourStarterProperties.class)： 启用对YourStarterProperties类型配置的支持
 * @ConditionalOnClass(YourStarterService.class)： 只有在类路径（classpath）中存在 YourStarterService 类时，YourStarterAutoConfiguration配置类才会生效。
 */
@Configuration
@EnableConfigurationProperties(YourStarterProperties.class)
@ConditionalOnClass(YourStarterService.class)
public class YourStarterAutoConfiguration {
    @Bean
    @ConditionalOnMissingBean // 当容器中没有这YourStarterService时，才会实例化这个YourStarterService
    public YourStarterService yourStarterService(YourStarterProperties properties) {
        return new YourStarterService(properties);
    }
}
